import 'package:flutter/material.dart';
import 'package:flutter_douban/main_page/class/page/classroom_category_page.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';

class ClassCategoryView extends StatefulWidget {
  const ClassCategoryView({Key? key}) : super(key: key);

  @override
  _ClassCategoryViewState createState() => _ClassCategoryViewState();
}

class _ClassCategoryViewState extends State<ClassCategoryView> {
  List titleList = ['面包','甜点','中式面点','特色小吃','家常菜','蛋糕','饮品','热销月饼','宝宝辅食','VIP免费'];
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 12,right: 12,top: 10),
      height: 140,
      child: GridView.builder(
          itemCount: titleList.length,
          physics: NeverScrollableScrollPhysics(),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            //横轴元素个数
              crossAxisCount: 5,
              //纵轴间距
              mainAxisSpacing: 15.0,
              //横轴间距
              crossAxisSpacing: 18.0,
              //子组件宽高长度比例
              childAspectRatio: 1.0),
          itemBuilder: (BuildContext context, int index) {
            //Widget Function(BuildContext context, int index)
            return _getItemContainer(titleList[index]);
          }),
    );
  }

  Widget _getItemContainer(String title) {
    return InkWell(
      child: Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset('assets/images/common/navi_item_share_moments.png',width: 30,height: 30,),
            SizedBox(height: 4,),
            Text(title,
                style: TextStyle(
                  fontSize: 12,
                  color: Colors.black54,)),
          ],
        ),
      ),
      onTap: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (_) {
          return ClassRoomCategoryPage(titleStr: title,);
        }));
      },
    );
  }
}
